package com.admin.service

import com.admin.dao.ThemeClassDao
import com.data.annotation.NoargAnnotation
import com.data.annotation.OpenAnnotation
import com.data.bean.ThemeClass
import com.data.util.CheckDataUtils
import com.data.util.DatabaseIdUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

import java.util.Date

/**
 * FileName: ThemeClassService
 * Author:   HingLo
 * Date:     2017/11/6 11:04
 * Description: 主题分类管理的服务层
 */
@Service
@OpenAnnotation
@NoargAnnotation
class ThemeClassService {
    @Autowired
    private var themeClassDao: ThemeClassDao? = null

    fun listThemeClassService(): List<ThemeClass> = themeClassDao!!.listThemeClassDao()

    fun changeThemeClassService(id: String, name: String): Boolean {
        return if (CheckDataUtils.stringUtilsID(id) && CheckDataUtils.stringUtils(name)) {
            themeClassDao!!.changeThemeClassDao(id, name) > 0
        } else false
    }

    fun submitThemeClassService(themeClass: ThemeClass): Boolean {
        if (CheckDataUtils.stringUtils(themeClass.name ?: "")) {
            themeClass.id = DatabaseIdUtils.dataIdOne
            themeClass.date = Date()
            return themeClassDao!!.saveMassageDao(themeClass)
        }
        return false
    }

    fun deleteThemeClassService(id: String): Boolean {
        return if (CheckDataUtils.stringUtilsID(id)) {
            this.themeClassDao!!.deleteThemeClassDao(id) > 0
        } else false
    }
}
